{extend name="property@base"/}
{block name='content'}
	<!-- 派工/待工单表单开始 -->
	<div class="weui-cells weui-cells_form">
	  <div class="weui-cell weui-cell_switch">
	    <div class="weui-cell__bd">是否待工</div>
	    <div class="weui-cell__ft">
	      <input class="weui-switch" id='choseRest' name='choseRest' disabled type="checkbox" {if condition="input('type')!='work'"}checked='checked'{/if} >
	      <input type="hidden" id="choseRestVal" name="btn1" {if condition="input('type')!='work'"}value="on"{else/}value="off"{/if}  />
	    </div>
	  </div>
	  <!-- 派工内容start -->
	  <form action="{:url('record_list/save_work')}" back="true" method='post' class='ajax_submit' id='workForm'>
			<input type='hidden' name='id' value='{$workrecord.id|default=""}'/>
			{:token('hash')}
			<div class="weui-cell">
			  <div class="weui-cell__hd"><label class="weui-label">选择工种</label></div>
			  <div class="weui-cell__bd">
			    <input class="weui-input" type="text" name='type' id='cate1' value='{$workrecord.type|default=""}' placeholder='选择工种' readonly>
			  </div>
			</div>
			<div class="weui-cell">
			  <div class="weui-cell__hd"><label class="weui-label">派工内容</label></div>
			  <div class="weui-cell__bd">
			    <input class="weui-input" type="text" name='content' id='cate2' value='{$workrecord.content|default=""}' placeholder='选择派工内容' readonly>
			  </div>
			</div>
			<div class="weui-cell">
			  <div class="weui-cell__hd"><label class="weui-label">日期</label></div>
			  <div class="weui-cell__bd">
			    <input class="weui-input" type="text" name='date' id='datepicker' value='{$workrecord.date|default=$date}' readonly>
			  </div>
			</div>
			<div class="weui-cell">
				<div class="weui-cell__hd"><label class="weui-label">工作时段</label></div>
				<div class="weui-cell__bd" >
				  <input class="weui-input" style='text-align:center;' name='starttime' value='{$workrecord.starttime|default=""}' type="text" id='datetime-picker-start' readonly>
				</div>
				<div class="weui-cell__hd"><label class="">—</label></div>
				<div class="weui-cell__bd">
				  <input class="weui-input" style='text-align:center;' type="text" name='endtime' value='{$workrecord.endtime|default=""}' id='datetime-picker-end' readonly>
				</div>
			 </div>
			 <div class="weui-cell">
			   <div class="weui-cell__hd"><label class="weui-label">工作用时</label></div>
			   <div class="weui-cell__bd">
			     <input class="weui-input" type="text" pattern="" name='worktime' name='usetime' value='{$workrecord.worktime|default=""|round=###,2}' placeholder="" readonly>
			   </div>
			 </div>
			 <div class="weui-cell">
			   <div class="weui-cell__hd"><label class="weui-label">效率系数</label></div>
			   <div class="weui-cell__bd">
			     <input class="weui-input" type="text" pattern="" placeholder="" name='efficiency' value='{$workrecord.efficiency|default=""|round=###,2}' readonly>
			   </div>
			 </div>
			 <div class="weui-cell">
			   <div class="weui-cell__hd"><label class="weui-label">难度系数</label></div>
			   <div class="weui-cell__bd">
			     <input class="weui-input" type="text" pattern="" name='coefficient' name='coefficient' placeholder="难度系数" value='{$workrecord.coefficient|default=""|round=###,2}' readonly>
			   </div>
			 </div>
			 <div class="weui-cell">
			   <div class="weui-cell__hd"><label class="weui-label">环境系数</label></div>
			   <div class="weui-cell__bd">
			     <input class="weui-input" type="text" pattern="" name='environmental' placeholder="" value='{$workrecord.environmental|default=""|round=###,2}' readonly>
			   </div>
			 </div>
			<div class="weui-cells__title">备注：</div>
			<div class="weui-cells weui-cells_form">
				<div class="weui-cell">
				  <div class="weui-cell__bd">
				    <textarea class="weui-textarea" placeholder="请输入备注内容" name='remark' rows="3">{$workrecord.remark|default=""}</textarea>
				    <!-- <div class="weui-textarea-counter"><span>0</span>/200</div> -->
				  </div>
				</div>
			</div>
			<div class='weui-btn-area'>
			 	<button type='submit' class="weui-btn weui-btn_primary">提交</button>
			</div>
	  </form>
	  <!-- 派工内容end -->
	  <!-- 待工内容start -->
	  	<form action="{:url('record_list/save_rest')}" back="true" class='ajax_submit' method='post' id='restForm'>
	  		<input type='hidden' name='id' value='{$restrecord.id|default=""}'/>
	  		{:token('hash')}
	  		<div class="weui-cell">
			  <div class="weui-cell__hd"><label class="weui-label">日期</label></div>
			  <div class="weui-cell__bd">
			    <input class="weui-input" type="text" id='datepicker2' name='date' value='{$restrecord.date|default=$date}' readonly>
			  </div>
			</div>
			<div class="weui-cell">
				<div class="weui-cell__hd"><label class="weui-label">待工时段</label></div>
				<div class="weui-cell__bd" >
				  <input class="weui-input" style='text-align:center;' name='starttime' value='{$restrecord.starttime|default=""}' type="text" id='datetime-picker-start2' readonly>
				</div>
				<div class="weui-cell__hd"><label class="">—</label></div>
				<div class="weui-cell__bd">
				  <input class="weui-input" style='text-align:center;' type="text" name='endtime' value='{$restrecord.endtime|default=""}' id='datetime-picker-end2' readonly>
				</div>
			 </div>
			 <div class="weui-cell">
			   <div class="weui-cell__hd"><label class="weui-label">待工时长</label></div>
			   <div class="weui-cell__bd">
			     <input class="weui-input" type="text" pattern="" name='resttime' placeholder="" value="{$restrecord.resttime|default=''|round=###,2}" readonly>
			   </div>
			 </div>
			 <div class="weui-cell">
			   <div class="weui-cell__hd"><label class="weui-label">待工系数</label></div>
			   <div class="weui-cell__bd">
			     <input class="weui-input" type="text" pattern="" name='efficiency' value="{$restrecord.efficiency|default=''|round=###,2}" placeholder="" value='0.95' readonly>
			   </div>
			 </div>
			<div class="weui-cells__title">待工原因：</div>
			<div class="weui-cells weui-cells_form">
				<div class="weui-cell">
				  <div class="weui-cell__bd">
				    <textarea class="weui-textarea" name='remark' placeholder="请输入待工事由" rows="3">{$restrecord.remark|default=''}</textarea>
				  </div>
				</div>
			</div>
			<div class='weui-btn-area'>
			 	<button type='submit' class="weui-btn weui-btn_primary">提交</button>
			</div>
	  	</form>
	  <!-- 待工内容end -->
	</div>
	<!-- 派工单表单结束 -->
{/block}	
{block name='script'}
<script type='text/javascript'>
	$(function(){
		var type = "{:input('type')}";
		if(type!='work'){
			var val = $("#choseRestVal").val()
			$("#choseRestVal").val(val);
			if(val=='on'){
				$("#restForm").css({'display':'block'});
				$("#workForm").css({'display':'none'});
			}
			else{
				$("#workForm").css({'display':'block'});
				$("#restForm").css({'display':'none'});
			}
		}
		$("#cate1").select({
			title: "选择工种",
	   		items: {$worktypes},
	   		onChange:function(obj){
	   			if(obj.length>0){
	   				var workcontents = {$workcontents};
		   			var title = obj.values;
		   			$("input[name='coefficient']").val(0);
		   			$("#cate2").val("");
		   			$("#cate2").attr("data-values",0);
		   			$("#cate2").select("update",{
		   				title:"选择工作内容",
		   				items:workcontents[title]
		   			});
	   			}
	   		}
		});
		$("#cate2").select({
			title:"选择工作内容",
			items:["--请先选择工种--"],
			onChange:function(obj){
				if(obj.length>0){
					console.log(obj.values);
					$("input[name='coefficient']").val(obj.values);
				}
			}
		});
		
		$("#datepicker,#datepicker2").calendar();
		var timeobj = [
				       {
					         textAlign: 'center',
					         values: ['08','09',10,11,12,13,14,15,16,17,18]
					       },
					       {
						         textAlign: 'center',
						         values: [':'],
								 displayValues:['时']
						   },
					       {
					         textAlign: 'center',
					         values: ['00','05',10,15,20,25,30,35,40,45,50,55]
					       },
						   {
						         textAlign: 'center',
						         values: [''],
						         displayValues:['分']
						   }
					     ];
		var starttime = "{$workrecord.starttime|default=""}";
		var starttimeObj = starttime.split(" : ");
		$("#datetime-picker-start").picker({
			title:"选择工作开始时间",
			cols: timeobj,
			value:starttimeObj.length==2?[starttimeObj[0],":",starttimeObj[1],""]:"",
			onClose:function(){
				timediff($("#datetime-picker-start").val(),$("#datetime-picker-end").val(),$("input[name='worktime']"));
			}
		});
		var endtime = "{$workrecord.endtime|default=""}";
		var endtimeObj = endtime.split(" : ");
		$("#datetime-picker-end").picker({
			title:"选择工作结束时间",
			cols: timeobj,
			value:endtimeObj.length==2?[endtimeObj[0],":",endtimeObj[1],""]:"",
			onClose:function(){
				timediff($("#datetime-picker-start").val(),$("#datetime-picker-end").val(),$("input[name='worktime']"));
			}
		});
		var starttime2 = "{$restrecord.starttime|default=""}";
		var starttimeObj2 = starttime2.split(" : ");
		$("#datetime-picker-start2").picker({
			title:"选择待工开始时间",
			cols: timeobj,
			value:starttimeObj2.length==2?[starttimeObj2[0],":",starttimeObj2[1],""]:"",
			onClose:function(){
				timediff($("#datetime-picker-start2").val(),$("#datetime-picker-end2").val(),$("input[name='resttime']"));
			}
		});
		
		var endtime2 = "{$restrecord.endtime|default=""}";
		var endtimeObj2 = endtime2.split(" : ");
		$("#datetime-picker-end2").picker({
			title:"选择待工结束时间",
			cols: timeobj,
			value:endtimeObj2.length==2?[endtimeObj2[0],":",endtimeObj2[1],""]:"",
			onClose:function(){
				timediff($("#datetime-picker-start2").val(),$("#datetime-picker-end2").val(),$("input[name='resttime']"));
			}
		});
		
		function timediff(time1,time2,eleObj){
			var obj1 = time1.split(" : ");
			var obj2 = time2.split(" : ");
			
			var minutes = (obj2[0]-obj1[0])*60+(obj2[1]-obj1[1]);
			minutes = isNaN(minutes)?0:minutes;
			if(minutes<0){
				$.alert("开始时间不能晚于截止时间");
				minutes = 0;
			}
			var hours = (minutes/60).toFixed(2);
			eleObj.val(hours);
			console.log(minutes);
		}
	});
</script>
{/block}